package TraitementMessages;

/**
 * @class FriendRequestMessage
 * @author Hicham
 */
import ihm.main.Traitement;

import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

import com.lo23.data.objgroup.Friend;
import com.lo23.data.objinterface.LocalUser;

import mainProcess.MainProcessing;
import mainProcess.UserAction;

public class DeleteFriendMessage extends FriendMessage {

	static final long serialVersionUID = 23201024L;
	
	protected String senderLogin;

	public DeleteFriendMessage(String senderUID, String senderLogin) {
		super(senderUID);
		this.senderLogin = senderLogin;
	}

	@Override
	public void handleReceiption(MainProcessing mainProcessing) 
	{
		//author: Hicham
		LocalUser lUser = mainProcessing.getDataInterface().getLocalUser(null);

    	if(lUser == null)
    	{
    		Logger.getLogger(UserAction.class.getName()).log(Level.SEVERE, "Traitement : Local user Null");
    		return;
    	}
    	
    	List<Friend>  listFriend = lUser.getListFriends();
    	
    	boolean exist = false;
    	
    	for(Friend anFriend : listFriend)
    	{
    		if(anFriend.getuID().equals(senderUID))
    		{
    			exist = true;
    			break;
    		}
    	}
    	if(exist)
    	{
    		lUser.deleteFriend(senderUID);
    		
    		Traitement interfaceIHM = Traitement.getInstance();
    		interfaceIHM.friendDeleted( senderUID, senderLogin );
    	}
	}

}
